const themeAction = [
  {
    id: 'themeServer.default',
    name: '默认主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.setTheme('default')
    }
  },
  {
    id: 'themeServer.next',
    name: '下一个主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.next()
    }
  },
  {
    id: 'themeServer.prev',
    name: '上一个主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.prev()
    }
  },
  {
    id: 'themeServer.setTheme',
    name: '切换主题',
    type: 'theme',
    exec: (app, params) => {
      // params 是匹配结果的数组
      const result = params[2],
        order = parseInt(result)
        const numChar = {
          一: 1,
          二: 2,
          三: 3,
          四: 4,
          五: 5,
          六: 6,
          七: 7,
          八: 8,
          九: 9,
          十: 10
        }
      // 按顺序切换
      if (!isNaN(order)) {
        const themes = app.themeServer.callState('themes')
        if (themes.length < order) {
          app.themeServer.addWarn('Invalid theme')
        } else {
          app.themeServer.setTheme(themes[order - 1].value)
        }
        return
      }
      if (isNaN(result)) {
        let orderNum = numChar[result]
        if(!isNaN(orderNum)){
          const themes = app.themeServer.callState('themes')
          if (themes.length < orderNum) {
            app.themeServer.addWarn('Invalid theme')
          } else {
            app.themeServer.setTheme(themes[orderNum - 1].value)
          }
          return
        }
      }
      // 按主题名称切换
      // 仙境 江山如画 怀旧 靓丽
      switch (result) {
        case '仙境':
        case '森之仙境':
        case '深之仙境':
        case '生之仙境':
        case '声之仙境':
          app.themeServer.setTheme('forest')
          break
        case '江山如画':
          app.themeServer.setTheme('paint')
          break
        case '怀旧':
          app.themeServer.setTheme('oldtime')
          break
        case '靓丽':
        case '亮丽':
          app.themeServer.setTheme('beauty')
          break
        default:
          app.themeServer.addWarn('Invalid theme')
      }
    }
  },
  {
    id: 'themeServer.adjust',
    name: '调节主题',
    type: 'theme',
    exec: (app, params) => {
      const themeState = app.themeServer.getState(),
        curr = themeState.currentThemeValue,
        adjCurr = themeState.adjThemeValue
      let currTheme
      if (curr === adjCurr) {
        const currThemeCache = themeState.themes.filter((t) => {
          return t.value === curr
        })
        currTheme = {
          ...currThemeCache[0].config
        }
      } else {
        currTheme = {
          ...themeState.adjTheme
        }
      }
      // 加法
      function add(...rest) {
        return rest.reduce((acc, crr) => {
          return acc + crr
        })
      }
      // 减法
      function subt(p1, p2) {
        return p1 - p2
      }
      // todo 在这里修改参数
      // test
      const step = 5,
        operate = params[0] === '增加' ? add : subt,
        type = params[1],
        value = parseInt(params[2]) || step

      switch (type) {
        case '亮度':
          currTheme.brightness = operate(currTheme.brightness, value)
          break
        case '色相':
          currTheme.hueRotate = operate(currTheme.hueRotate, value)
          break
        case '饱和度':
          currTheme.saturate = operate(currTheme.saturate, value)
          break
      }
      // end
      app.themeServer.adjust('#cmlFilterContainer', currTheme)
    }
  },
  {
    id: 'themeServer.preview',
    name: '预览主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.applyTheme('#cmlFilterContainer', params)
    }
  },
  {
    id: 'themeServer.addTheme',
    name: '新增主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.addTheme(params)
    }
  },
  {
    id: 'themeServer.deleteTheme',
    name: '删除主题',
    type: 'theme',
    exec: (app, params) => {
      app.themeServer.deleteTheme(params)
    }
  },
  {
    id: 'control.setLoolAt',
    name: '3D控制',
    type: '3D',
    exec: (app, params) => {
      window.app.controls.setLookAt(params)
    }
  },
  {
    id: 'control.toggleAction',
    name: '3D切换动作',
    type: '3D',
    exec: (app, params) => {
      // console.log(params)
      window.app.controls.toggleAction(params)
    }
  },
  {
    id: 'control.changeWeather',
    name: '3D调整天气系统特效',
    type: '3D',
    exec: (app, params) => {
      // console.log(params)
      window.app.controls.changeWeather(params)
    }
  },
  {
    id: 'control.changeEffect',
    name: '切换特效',
    type: '3D',
    exec: (app, params) => {
      // console.log(params)
      window.app.controls.changeEffect(params)
    }
  },
  {
    id: 'control.changePoint',
    name: '切换视角',
    type: '3D',
    exec: (app, params) => {
      // console.log(params)
      window.app.controls.changePoint(params)
    }
  }
]
export default themeAction
